package com.ohuang.test_compose.page

import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.draggable
import androidx.compose.foundation.gestures.rememberDraggableState
import androidx.compose.foundation.layout.Column
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.InternalComposeApi
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.ExperimentalUnitApi
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.ohuang.test_compose.MainViewModel
import com.ohuang.test_compose.composeView.MotionLayoutAppBar

@OptIn(ExperimentalPermissionsApi::class, InternalComposeApi::class, ExperimentalUnitApi::class,
    ExperimentalMaterialApi::class, ExperimentalAnimationApi::class
)
@Composable
fun ConstraintLayoutPage(viewModel: MainViewModel= androidx.lifecycle.viewmodel.compose.viewModel()) {
    Column() {
        val motionLayoutProgress = remember { mutableStateOf(0.0f) }
        MotionLayoutAppBar(
            title = "Title",
            subTitle = "Subtitle",
            modifier=Modifier .draggable(
                    orientation = Orientation.Vertical,
            state = rememberDraggableState { delta ->
                val value = motionLayoutProgress.value
                var t=value+(0.01F*delta)
                if (t<0){
                    t= 0.0F
                }
                if (t>1){
                    t=1.0F
                }
                motionLayoutProgress.value=t
            }),
            backgroundColor = Color(0xFF214561),
            progress = motionLayoutProgress.value,
            onBackPressed = {
                viewModel.pageSliceManager.goBack()
            }
        )

    }
}